#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author: LiangChao
@email：kevinleong1011@hotmail.com

@desc: 
"""
import os

from makit.logging import FileHandler

from makitest.log import MakitestLogger


def on_fixture_start(fixture, context):
    if not _has_log_file(fixture.logger):
        project, config = fixture.project, fixture.project.config
        workspace = config.WORKSPACE
        project_name = config.name or project.name
        logger = MakitestLogger()
        logger.write_file(os.path.join(workspace, 'reports', project_name, fixture.name), mode='w')


def on_script_finished(script, context):
    pass


def _has_log_file(logger):
    for handler in logger.handlers:
        if isinstance(handler, FileHandler):
            return True
    return False
